package com.mtung.concurrent.thread;

/**
     * A thread state.  A thread can be in one of the following states:
     * <ul>
     * <li>{@link #NEW}<br>
     *     A thread that has not yet started is in this state.
     *     </li>
     * <li>{@link #RUNNABLE}<br>
     *     A thread executing in the Java virtual machine is in this state.
     *     </li>
     * <li>{@link #BLOCKED}<br>
     *     A thread that is blocked waiting for a monitor lock
     *     is in this state.
     *     </li>
     * <li>{@link #WAITING}<br>
     *     A thread that is waiting indefinitely for another thread to
     *     perform a particular action is in this state.
     *     </li>
     * <li>{@link #TIMED_WAITING}<br>
     *     A thread that is waiting for another thread to perform an action
     *     for up to a specified waiting time is in this state.
     *     </li>
     * <li>{@link #TERMINATED}<br>
     *     A thread that has exited is in this state.
     *     </li>
     * </ul>
     *
     * <p>
     * A thread can be in only one state at a given point in time.
     * These states are virtual machine states which do not reflect
     * any operating system thread states.
     *
     * @since   1.5
     * @see #getState
     */
    public enum State {
        /**
         * 线程对象创建了,但是还没有调用start()
         */
        NEW,

        /**
         * 线程处于可运行状态，但是这个可运行状态并不代表线程一定在虚拟机中执行。
         * 需要等待从操作系统获取到资源(比如处理器时间片)，才能真正的去运行
         */
        RUNNABLE,

        /**
         * 当前线程处于阻塞状态，
         * 正在等待另一个线程的monitor lock释放，才进入synchronized代码块或方法
         */
        BLOCKED,

        /**
         * 调用Object#wait() 、 Thread.join方法后当前线程处于等待状态，
         * 等待其他的线程执行特定的动作，才能从等待状态退出。
         * 比如：Object.wait()的线程需要等待其他线程调用Object.notify()、Object.notifyAll()才能退出
         * 比如：调用了Thread.join()的线程需要等待指定的线程执行完成才能退出等待状态。
         */
        WAITING,

        /**
         * 进入特定时间内的等待状态，等待一段指定的时间sleep(timed)、wait(timed)或者等待Thread.join(timed)的时间.
         * 到达指定时间点自动退出恢复到RUNNABLE状态
         */
        TIMED_WAITING,

        /**
         * 线程结束状态
         */
        TERMINATED;
    }